package com.test.java;

import java.util.HashMap;
import java.util.Scanner;

/**
 * 为了用事实说明挖掘机技术到底哪家强，PAT组织了一场挖掘机技能大赛。
 * 现请你根据比赛结果统计出技术最强的那个学校。
 * =============================================================
 * Version          Author          Date            Description
 * 1.0              白建         2017/12/27             创建
 * =============================================================
 */
public class Java_23
{

    public static void main(String[] args)
    {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        scanner.nextLine();

        String temp;
        String[] strings;
        int currentScore;
        for (int i = 0; i < N; i++)
        {
            temp = scanner.nextLine();
            strings = temp.split(" ");
            if (!map.containsKey(strings[0]))
            {
                map.put(strings[0], Integer.parseInt(strings[1]));
            }
            else
            {
                currentScore = map.get(strings[0]);
                map.put(strings[0], currentScore + Integer.parseInt(strings[1]));
            }
        }

        final String[] className = new String[1];
        final int[] maxScore = { 0 };
        map.forEach((k, v) -> {
            if (v > maxScore[0])
            {
                className[0] = k;
                maxScore[0] = v;
            }
        });

        System.out.println(className[0] + " " + maxScore[0]);
    }
}
